package com.emapp.lccode.view;

import android.content.DialogInterface;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.emapp.lccode.R;
import com.emapp.lccode.activity.LoginKtActivity;


public class ToLogin {
    private static AlertDialog.Builder mBuilder;
    private static AppCompatActivity mActivity;

    public static void showLogin(final AppCompatActivity activity) {
        if (mBuilder == null || activity != mActivity) {
            mBuilder = new AlertDialog.Builder(activity);
            View view = LayoutInflater.from(activity).inflate(
                    R.layout.tologin, null);
            mBuilder.setView(view);
            TextView textview = (TextView) view.findViewById(R.id.textview);
            textview.setText("当前操作需要登录才能完成,\n是否去登录");
            mBuilder.setPositiveButton("确定",
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent it = new Intent(activity,
                                    LoginKtActivity.class);
                            activity.startActivity(it);
                            activity.finish();
                        }
                    });
            mBuilder.setNegativeButton("取消",
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });
            mBuilder.create().show();
        } else
            mBuilder.show();
    }
}
